package com.fs.adapters;

import java.util.List;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;
import android.graphics.drawable.Drawable;
import android.os.Handler;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Toast;

import com.example.studentmanagersystem.R;
import com.fs.myview.AccountListView;
import com.fs.po.UserData;

public class AccountAdapter extends BaseAdapter {

	private List<UserData> list;
	private Context context;
	private Bitmap buttonBitmap,checkButton;
	private Drawable buttonDrawable,checkDrawable;
	private String user;
	Handler handler;

	public AccountAdapter(Context context) {
		this.context = context;
		this.initImage();
	}

	
	private void initImage() {

		this.initButtonBimap();
		this.updateBitmap();
		this.seleteBitmap();
		this.addBitmap();
		this.initLayoutBg();
	}

	private Bitmap bgBitmap;
	private Drawable bgDrawable;

	
	private void initLayoutBg() {
		this.bgBitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.radio_tab_view_layout2_bg);
		this.bgDrawable = new BitmapDrawable(context.getResources(), bgBitmap);

	}

	private Bitmap addBitmap;
	private Drawable addDrawable;

	
	private void addBitmap() {
		this.addBitmap = BitmapFactory.decodeResource(context.getResources(),R.drawable.user_add);
		this.addDrawable = new BitmapDrawable(context.getResources(),addBitmap);

	}

	private Bitmap deleteBitmap;
	private Drawable deleteDrawable;

	
	private void seleteBitmap() {
		this.deleteBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.user_delete);
		this.deleteDrawable = new BitmapDrawable(context.getResources(), deleteBitmap);
	}

	private Bitmap updateBitmap;
	private Drawable updateDrawable;

	
	private void updateBitmap() {
		this.updateBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.user_updata);
		this.updateDrawable = new BitmapDrawable(context.getResources(), updateBitmap);
	}

	
	private void initButtonBimap() {
		this.buttonBitmap = BitmapFactory.decodeResource(context.getResources(), R.drawable.radio_tab_view_unchecked);
		this.buttonDrawable = new BitmapDrawable(context.getResources(), buttonBitmap);
	}
	
	
	public void setData(List<UserData> list,String user,Handler handler) {
		
		this.list = list;
		this.size = list.size();
		this.user=user;
		
		this.handler=handler;
		
		System.out.println(list.size()+"LLLL"+user);
	}

	int size = 0;

	@Override
	public int getCount() {

		return size;
	}

	@Override
	public Object getItem(int position) {

		return position;
	}

	@Override
	public long getItemId(int position) {

		return position;
	}

	@Override
	public View getView(int location, View view, ViewGroup parent) {

		AccountListView m_RadioView = new AccountListView(context);
		 
		m_RadioView.setImage(buttonDrawable, bgDrawable,addDrawable, updateDrawable, deleteDrawable);
		
		
		m_RadioView.setInfor(list.get(location),user,handler);
		

		return m_RadioView;
	}
}
